errors = {}

define = (code, message)-> errors[code] = message

define "UserNotExisted", "用户不存在"
define "PasswordNotMatch", "密码不匹配"

define 'UsernamePasswordRequired', "请填写用户名密码"
define 'TruenameRequired', "请填写真实姓名"



define 'TopicNotFound', "帖子不存在!"

define "InternalError", "服务器出错！"

class MyError extends Error
    constructor: (@code, message)->
        @message = errors[@code] || message
        super @message
    describe: ->
        {code: @code, message: @message, defaultMessage: @message}

class UserError extends MyError
    constructor: (@code, message)->
        super @code, message

class SystemError extends MyError
    constructor: (@code, message)->
        super @code, message
        this.stack = (new Error()).stack

exports.UserError = UserError
exports.SystemError = SystemError